home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 072 (1988-11-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 072 (1988-11-15)(Ossowski, Stefan)(DE)(PD).adf / Pcopy / pc1.c < prev    next >
C/C++ Source or Header  |  1988-08-14  |  7KB  |  285 lines

  1. /*  pc1.c -  Some other functions  */
  2.  
  3. #include "pcopy.h"
  4.  
  5. /*  Our startup is calling it, so we why shouldn't we define it?
  6.  */
  7. void MemCleanup(){}
  8.  
  9.  
  10. /*
  11.  *  Open all windows, open a Console device for the history window and
  12.  *  a port to it.
  13.  */
  14.  
  15. OpenUser()
  16. {
  17.   TxT[SHORTTIME]='\0';  /*  cut the string just before the sizing gadgets */
  18.   WT=OpenWindow(&NwT);
  19.   W1=OpenWindow(&Nw1);
  20.   W0=OpenWindow(&Nw0);
  21.   WH=OpenWindow(&NwH);
  22.   WS=OpenWindow(&NwS);
  23.  
  24.   if (!(WT&&W1&&W0&&WH&&WS)) return(-1);  /* any missing window? */
  25.  
  26.   if (!(MPHist=CreatePort("History",0))) return(-1);
  27.   if (!(IOHist=CreateStdIO(MPHist))) return(-1);
  28.   IOHist->io_Data=(APTR)WH;
  29.   IOHist->io_Length=sizeof(*WH);
  30.   return(OpenDevice("console.device",0,IOHist,0));
  31. }
  32.  
  33.  
  34. /*
  35.  *  The same as the preceding function but now  !
  36.  */
  37.  
  38. void CloseUser()
  39. {
  40.   if (IOHist){
  41.     if (IOHist->io_Device) CloseDevice(IOHist);
  42.     DeleteStdIO(IOHist);
  43.   }
  44.   if (MPHist) DeletePort(MPHist);
  45.   if (WT) CloseWindow(WT);
  46.   if (WH) CloseWindow(WH);
  47.   if (W1) CloseWindow(W1);
  48.   if (W0) CloseWindow(W0);
  49.   if (WS) CloseWindow(WS);
  50. }
  51.  
  52.  
  53. /*
  54.  *  We donot want to refresh all gadgets, so a patch again
  55.  */
  56.  
  57. void RefOneGadget(G,W,R)
  58. struct Gadget *G; struct Window *W; struct Requester *R;
  59. {
  60.   RemoveGadget(W,G);
  61.   AddGadget(W,G,-1);
  62.   RefreshGadgets(G,W,R);
  63. }
  64.  
  65.  
  66. /*
  67.  *  This way you should make a beep!  It's the multitasking way. It's a
  68.  *  decent way.  No pumping words into a DAC which was just busy converting
  69.  *  The Dutch National Anthem.
  70.  */
  71.  
  72. Beep(type)
  73. short type;
  74. {
  75.   /* We need these to get the adress of unmerged memory  */
  76.   static UBYTE *SDA=SoundData;
  77.   static UBYTE *SDA1=SoundData1;
  78.  
  79.   UBYTE sunit=0x0f;
  80.   short done=0;
  81. /*  
  82.   if (!BeepAllowed) return(0);  
  83. */  
  84.   if (Sound.ioa_Request.io_Message.mn_ReplyPort=CreatePort("p3",0)){
  85.     Sound.ioa_Request.io_Message.mn_Node.ln_Pri=BEEP_PRI;
  86.     Sound.ioa_Data=&sunit;
  87.     Sound.ioa_Length=(ULONG)sizeof(sunit);
  88.     Sound.ioa_Request.io_Flags=ADIOF_NOWAIT;
  89.     if (!OpenDevice(AUDIONAME,0L,&Sound,0L)){
  90.  
  91.       Sound.ioa_Request.io_Command=CMD_WRITE;
  92.       Sound.ioa_Request.io_Flags=ADIOF_PERVOL | IOF_QUICK;
  93.       Sound.ioa_Data=SDA;
  94.       Sound.ioa_Length=SDA1-SDA;
  95. /*
  96.       Sound.ioa_Data=GetSoundDataAddress();
  97.       Sound.ioa_Length=GetSoundDataSize();
  98. */
  99.       Sound.ioa_Volume=64;
  100.       
  101.       if (type){         /*  alarm tune  */
  102.         DoBeep(406,26);
  103.         Delay(1);
  104.         DoBeep(406,45);
  105.         DoBeep(304,35);
  106.         DoBeep(406,26);
  107.         DoBeep(304,35);
  108.         DoBeep(406,80);
  109.       } else{            /*  ready tune  */
  110.         DoBeep(406,32);
  111.         Delay(1);
  112.         DoBeep(406,110);
  113.       }
  114.  
  115.       CloseDevice(&Sound);
  116.       done=1;
  117.     }
  118.     DeletePort(Sound.ioa_Request.io_Message.mn_ReplyPort);
  119.   }
  120.   if (!done)  DisplayBeep(IntuitionBase->ActiveScreen);
  121.                          /*  if no Sound device at least this */
  122.   return((int)done);
  123. }
  124.  
  125.  
  126. void DoBeep(period,cycles)
  127. {
  128.   Sound.ioa_Period=period;
  129.   Sound.ioa_Cycles=cycles;
  130.   BeginIO(&Sound);
  131.   WaitIO(&Sound);
  132. }
  133.  
  134.  
  135. void ConPutStr(req,str)
  136. struct IOStdReq *req;
  137. char *str;
  138. {
  139.   register int saveD7; /*  Is it true that DoIO() to a console trashes D7?  */
  140.   req->io_Command=CMD_WRITE;
  141.   req->io_Data=(APTR)str;
  142.   req->io_Length=-1;
  143.   DoIO(req);
  144. }
  145.  
  146.  
  147. /*
  148.  *  AutoRequest is not handsome enough, we make it nice here.
  149.  */
  150.  
  151. Request(text0,text1,text2,text3)
  152. char *text0, *text1, *text2, *text3;
  153. {
  154.   static struct IntuiText ITBod1={ 0,0,JAM1,10,14,0,0,0 };
  155.   static struct IntuiText ITBod0={ 0,0,JAM1,10, 4,0,0,0 };
  156.   static struct IntuiText  ITPos={ 0,0,JAM1, 6, 3,0,0,0 };
  157.   static struct IntuiText  ITNeg={ 0,0,JAM1, 6, 3,0,0,0 };
  158.   register int width0, width1;
  159.  
  160.   ITBod0.IText=text0;
  161.   ITPos.IText=text2;
  162.   ITNeg.IText=text3;
  163.   if (ITBod1.IText=text1){
  164.     ITBod0.NextText=&ITBod1;
  165.     width1=IntuiTextLength(&ITBod1)+48;
  166.   } else{
  167.     ITBod0.NextText=0;
  168.     width1=0;
  169.   }
  170.   width0=IntuiTextLength(&ITBod0)+48;
  171.   if (width0<152) width0=152;     /* a minimum width  */
  172.   return (AutoRequest(WS,&ITBod0,&ITPos,&ITNeg,
  173.            GADGETDOWN,GADGETDOWN,(width1<width0)?width0:width1,60));
  174. }
  175.  
  176.  
  177. /*
  178.  *  Careful analises of some Manx "objects", delivered this function.
  179.  */
  180.  
  181. long dos_packet(port, type, arg1, arg2)
  182. struct MsgPort *port;  long type, arg1, arg2;
  183. {
  184.   register struct StandardPacket *sp;
  185.   register struct MsgPort *rp, *CreatePort();
  186.   long ret;
  187.  
  188.   ret=0;
  189.   if (rp=CreatePort(0L,0L)){
  190.     if (sp=(struct StandardPacket *)
  191.     AllocMem((long)sizeof(struct StandardPacket),PUBCLR)){
  192.       sp->sp_Msg.mn_Node.ln_Name=(char *)&sp->sp_Pkt;
  193.       sp->sp_Pkt.dp_Link=&sp->sp_Msg;
  194.       sp->sp_Pkt.dp_Port=rp;
  195.       sp->sp_Pkt.dp_Type=type;
  196.       sp->sp_Pkt.dp_Arg1=arg1;
  197.       sp->sp_Pkt.dp_Arg2=arg2;
  198.       PutMsg(port,&sp->sp_Msg);
  199.       WaitPort(rp);
  200.       GetMsg(rp);
  201.       ret=sp->sp_Pkt.dp_Res1;
  202.       FreeMem(sp,(long)sizeof(*sp));
  203.     }
  204.     DeletePort(rp);
  205.   }
  206.   return(ret);
  207. }
  208.  
  209.  
  210. /*
  211.  *  Some people donot have a df1:, but a df2:. Thats why this drive
  212.  *  selection function is implemented. It builds up a requesterlike
  213.  *  window, asking the user to select two drives. If he did not select
  214.  *  them, ignore his done pushes. Then check if the names are not
  215.  *  assigned to the same drive.
  216.  */
  217.  
  218. AskDrives(){
  219.   ULONG proc;
  220.   struct InfoData *Info;
  221.   struct Window *WR;
  222.   short nr,i,dok,error;
  223.   char *dname;
  224.   
  225.   if (!(Info=(struct InfoData *)AllocMem((long)sizeof(struct InfoData),
  226.     MEMF_PUBLIC|MEMF_CLEAR))) return(-1);
  227.  
  228.   if (WR=OpenWindow(&NwR)){
  229.     for (nr=0;nr!=2;){
  230.       while (!(GDONE.Flags&SELECTED)) ;
  231.       GDONE.Flags&=~SELECTED;
  232.       for (nr=0,i=0;i<NDRIVES;++i) if (GList[i]->Flags&SELECTED) ++nr;
  233.     }
  234.     CloseWindow(WR);   /*  two names were selected, now get their #'s */
  235.     for (i=0,nr=0,error=0;i<NDRIVES;++i){
  236.       if (GList[i]->Flags&SELECTED){
  237.         dname=GList[i]->GadgetText->IText;
  238.         if (proc=DeviceProc(dname)){
  239.           if (dok=dos_packet(proc,ACTION_DISK_INFO,((ULONG)Info)>>2)){
  240.             DriveName[nr]=dname;
  241.             DriveNr[nr++]=Info->id_UnitNumber;
  242.           }
  243.         }
  244.         if (!(proc&&dok)) ++error;
  245.       }
  246.     }
  247.   } else error=-1;  /*  no window  */
  248.   FreeMem(Info,(long)sizeof(struct InfoData));
  249.   return(error||(DriveNr[0]==DriveNr[1]));
  250. }
  251.  
  252.  
  253. /*
  254.  *  Quite simple: a block of 1 kB is shifted over 32 bytes, to make place
  255.  *  for the new name.
  256.  */
  257.  
  258. void EnterHist(name)
  259. char *name;
  260. {
  261.   register ULONG *s,*d;
  262.   register short i;
  263.   s=(ULONG *)(Hist+((MHIST-1)*MVOLNAME));
  264.   d=(ULONG *)(Hist+(MHIST*MVOLNAME));
  265.   for (i=0;i<((MHIST-1)*MVOLNAME/4);++i) *(--d)=*(--s);
  266.   strncpy(Hist,name,MVOLNAME-1);
  267. }
  268.  
  269.  
  270. /*
  271.  *  Here the Copy History window is completely written over again.
  272.  */
  273.  
  274. void RefHist()
  275. {
  276.   short lines;
  277.   ConPutStr(IOHist,"\x0c");  /* clear screen  */
  278.   for (lines=(WH->Height-12)/8;lines>=0;--lines){
  279.     ConPutStr(IOHist,"\n ");
  280.     ConPutStr(IOHist,&Hist[lines*MVOLNAME]);
  281.   }
  282. }
  283.  
  284. /*  end of pc1.c  */
  285.